//
//  LGPatientWeightCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/6.
//

#import "LGPatientWeightCell.h"

#define weightCenterX      viewPix(95)+iPadMargin(20)
#define waistlineCenterX   viewPix(186)+iPadMargin(20)
#define BMICenterX         (Screen_W - viewPix(32) - viewPix(70) - iPadMargin(80))

@interface LGPatientWeightCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UILabel *weightLabel;
/**   */
@property (nonatomic , strong)UIButton *weightStatus;
/**   */
@property (nonatomic , strong)UILabel *waistlineLabel;
/**   */
@property (nonatomic , strong)UIButton *waistlineStatus;
/**   */
@property (nonatomic , strong)UILabel *BMILabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;

@end

@implementation LGPatientWeightCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.timeLabel.text = dataDic[@"record_time"];
    //体重
    self.weightLabel.text = LGNSString(dataDic[@"weight"]);
    NSString *weightStatus = LGNSString(dataDic[@"weightdiffstatus"]);
    self.weightStatus.hidden = (weightStatus.length>0)?NO:YES;
    self.weightStatus.selected = [weightStatus isEqualToString:@"up"]?YES:NO;
    [self.weightStatus setTitle:LGNSString(dataDic[@"weightdiffvalue"]) forState:UIControlStateNormal];
    //腰围
    self.waistlineLabel.text = LGNSString(dataDic[@"waistline"]);
    NSString *waistlineStatus = LGNSString(dataDic[@"waistlinediffstatus"]);
    self.waistlineStatus.hidden = (waistlineStatus.length>0)?NO:YES;
    self.waistlineStatus.selected = [waistlineStatus isEqualToString:@"up"]?YES:NO;
    [self.waistlineStatus setTitle:LGNSString(dataDic[@"waistlinediffvalue"]) forState:UIControlStateNormal];
    //BMI
    self.BMILabel.text = LGNSString(dataDic[@"bmi"]);
    NSString *status = LGNSString(dataDic[@"bmi_status"]);
    NSDictionary *titleDic = @{@"0":@"正常",@"1":@"偏胖",@"2":@"肥胖",@"3":@"偏瘦"};
    NSDictionary *colorDic = @{@"0":@"#429BFF",@"1":@"#FF9704",@"2":@"#E53C39",@"3":@"#3DC997"};
    self.statusLabel.text = titleDic[status];
    self.statusLabel.textColor = [UIColor colorWithString:colorDic[status]];
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.weightLabel];
    [self.baseView addSubview:self.weightStatus];
    [self.baseView addSubview:self.waistlineLabel];
    [self.baseView addSubview:self.waistlineStatus];
    [self.baseView addSubview:self.BMILabel];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.centerY.equalTo(self.baseView);
    }];
    [self.weightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.baseView.mas_left).offset(weightCenterX);
        make.centerY.equalTo(self.timeLabel);
    }];
    [self.weightStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.weightLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.weightLabel);
        make.width.equalTo(@(viewPix(45)));
    }];
    [self.waistlineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.baseView.mas_left).offset(waistlineCenterX);
        make.centerY.equalTo(self.timeLabel);
    }];
    
    [self.waistlineStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.waistlineLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.waistlineLabel);
        make.width.equalTo(@(viewPix(45)));
    }];
    
    [self.BMILabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.baseView.mas_left).offset(BMICenterX);
        make.centerY.equalTo(self.timeLabel);
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.BMILabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.BMILabel);
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor colorWithString:@"#F5FBFF"];
    }
    return _baseView;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UILabel *)weightLabel{
    if(!_weightLabel){
        _weightLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _weightLabel;
}

-(UIButton *)weightStatus{
    if(!_weightStatus){
        _weightStatus = [UIButton buttonWithTitle:@"" titleFont:LGFont(14) normalColor:@"#429BFF" selectColor:@"#E53C39"];
        [_weightStatus setImage:[UIImage imageNamed:@"体重-下降"] forState:UIControlStateNormal];
        [_weightStatus setImage:[UIImage imageNamed:@"体重-上升"] forState:UIControlStateSelected];
        _weightStatus.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _weightStatus;
}

-(UILabel *)waistlineLabel{
    if(!_waistlineLabel){
        _waistlineLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _waistlineLabel;
}

-(UIButton *)waistlineStatus{
    if(!_waistlineStatus){
        _waistlineStatus = [UIButton buttonWithTitle:@"" titleFont:LGFont(14) normalColor:@"#429BFF" selectColor:@"#E53C39"];
        [_waistlineStatus setImage:[UIImage imageNamed:@"体重-下降"] forState:UIControlStateNormal];
        [_waistlineStatus setImage:[UIImage imageNamed:@"体重-上升"] forState:UIControlStateSelected];
        _waistlineStatus.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _waistlineStatus;
}

-(UILabel *)BMILabel{
    if(!_BMILabel){
        _BMILabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _BMILabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _statusLabel;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
